package com.ztz.mynewdemo.utils;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * Created by wqewqe on 2018/3/25.
 */

public class KeyBoardUtils {
    //打开键盘
    public static void openKeyBoard(Context context, EditText editText){
        InputMethodManager imm= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        assert imm!=null;
        imm.showSoftInput(editText,InputMethodManager.RESULT_SHOWN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
    //关闭键盘
    public static void closeKeyBoard(Context context,EditText editText){
        InputMethodManager imm= (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        assert imm!=null;
        imm.hideSoftInputFromWindow(editText.getWindowToken(),0);
    }
}
